﻿using System;
using UnityEngine;
using UnityEngine.UI;

namespace com.yoozoo.gta.Extension.UGUI.ScreenOrientationEx
{
    [System.Serializable]
    public class AspectRatioFitterAdaptConfig
    {
        public AspectRatioFitter.AspectMode aspectMode;
        public float aspectRatio;

        //重写Equals方法
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            AspectRatioFitterAdaptConfig other = (AspectRatioFitterAdaptConfig)obj;
            // Compare aspectMode properties
            if (aspectMode != other.aspectMode)
            {
                return false;
            }

            // Compare aspectRatio properties
            if (Math.Abs(aspectRatio - other.aspectRatio) > 0.001f)
            {
                return false;
            }

            return true;
        }
        //生成GetHashCode方法   
        public override int GetHashCode()
        {
            int hash = 17;
            hash = hash * 23 + aspectMode.GetHashCode();
            hash = hash * 23 + aspectRatio.GetHashCode();
            return hash;
        }
    }
    [DisallowMultipleComponent]
    public class AspectRatioFitterAdapter : AdaptBase<AspectRatioFitterAdaptConfig, AspectRatioFitter>
    {
        protected override void CopyProperty(AspectRatioFitterAdaptConfig config)
        {
            base.CopyProperty(config);
            config.aspectMode = mComponent.aspectMode;
            config.aspectRatio = mComponent.aspectRatio;
        }

        protected override void ApplyConfig(AspectRatioFitterAdaptConfig config)
        {
            base.ApplyConfig(config);
            mComponent.aspectMode = config.aspectMode;
            mComponent.aspectRatio = config.aspectRatio;
        }
    }
}